package model.dao;

import model.entity.Book;
import org.junit.Test;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;

import java.util.List;

public class SearchAllDaoImpl implements SearchAllDao{

    private JdbcTemplate template;

    public SearchAllDaoImpl(JdbcTemplate template) {
        this.template = template;
    }
    public SearchAllDaoImpl() {
        this.template = new JdbcTemplate(BaseDao.getDataSource());
    }

    @Override
    public List<Book> searchAll() {
        String sql = "select * from books";
        List<Book> books = template.query(sql,  new BeanPropertyRowMapper<Book>(Book.class));
        return books;
    }

    @Test
    public void test()
    {
        System.out.println(searchAll());
    }
}
